<%@ page isELIgnored="false" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<script type="text/javascript">
	jQuery(function(){
		$('#emoney').numberspinner({onChange:function(){
			doCount();
		}});
		$('#trade').numberspinner({onChange:function(){
			setGive();
		}});
		$('#money').numberspinner({onChange:function(){
			doCount();
		}});
		setTax();
		setTimeout('disable()');
	});
	function disable(){
		$('#emoney').numberspinner('disable');
		$('#cardpassword').validatebox('remove');
		$('#confirmPassword').validatebox('remove');
		$('#cardpassword').attr("readonly",true);
		$('#confirmPassword').attr("readonly",true);
	}
	function enable(obj){
		if(obj.checked){
			$('#emoney').numberspinner('enable');
			$('#cardpassword').validatebox('reduce');
			$('#confirmPassword').validatebox('reduce');
			$('#cardpassword').attr("readonly",false);
			$('#confirmPassword').attr("readonly",false);
		}else{
			$('#cardpassword').val("");
			$('#confirmPassword').val("");
			$('#cardpassword').attr("readonly",true);
			$('#confirmPassword').attr("readonly",true);
			$('#cardpassword').validatebox('remove');
			$('#confirmPassword').validatebox('remove');
			$('#emoney').numberspinner('setValue','0');
			$('#emoney').numberspinner('disable');
		}
	}
	function addOrUpdateUser(){
		if(!writeMoneyCard(($('#money').val()-0))) return;
		if($('#confirmPassword').val()!=$('#cardpassword').val()){
			$.messager.show({
			       title: '提示',
			       msg: "密码不一致",
			       timeout: 3000,
			       showType: 'slide'
			 });	
			return false;
		}
		var r = $('#abaForm').form('validate');
		if(!r) {
			return false;
		}
		$.post("aba/addOrUpdate",$("#abaForm").serializeArray(),function(data){
			$('#MyPopWindow').window('close');
			$('#abaTable').datagrid('reload');  
			$.messager.alert('提示',data.mes,'info');
		});
	}
	
	$.extend($.fn.validatebox.methods, { 

		remove: function(jq, newposition){ 

		    return jq.each(function(){ 

		        $(this).removeClass("validatebox-text validatebox-invalid").unbind('focus').unbind('blur');

		    }); 

		},
		reduce: function(jq, newposition){ 

		    return jq.each(function(){ 

		       var opt = $(this).data().validatebox.options;

		       $(this).addClass("validatebox-text").validatebox(opt);

		    }); 

		}  
		});
	
	
	function doCount(){
		var emoney = $('#emoney').val()-0;
		var money = $('#money').val()-0;
		var selltax = $('#selltax').val()-0;
		var mustMoney = emoney+money+selltax;
		$('#mustMoney').text(mustMoney);
		$('#give').text(0);
		$('#trade').numberspinner('setValue',mustMoney);
	}
	function setGive(){
		var emoney = $('#emoney').val()-0;
		var money = $('#money').val()-0;
		var selltax = $('#selltax').val()-0;
		var trade = $('#trade').val()-0;
		var mustMoney = emoney+money+selltax;
		$('#give').text(trade-mustMoney);
	}
	function setTax(){
		var tax = '${ json.credit}';
		tax = eval('('+tax+')');
		$('#selltax').val(tax['1']);
		return tax['1'];
	}
	function readCardInfo(){
		$('#abaid_pop').val(findNormalCard());
		$('#money').numberspinner('setValue',findMoneyCard());
	}
</script>
<!-- 验证还是jquery-validation好用，这里省事没用 -->
<form id="abaForm" method="post" style="margin: 10;text-align: center;">
	<table>
		<tr><td><input name="version" type="hidden"><input name="creatuserid" type="hidden" value="<sec:authentication property="name"/>" ><input name="userid" type="hidden" id="userid"><input name="cardkey" type="hidden"  id="cardkey"> </td></tr>
		<tr><td>一卡通编号：</td><td><input name="abaid" id="abaid_pop" style="width: 200" class="easyui-validatebox" required="true"> </td></tr>
		<tr><td>是否开启电子账户：</td><td><input type="checkbox" onclick="enable(this);" value="1" name="eflag"></td></tr>
		<tr><td>密码：</td><td><input readonly="readonly" name="cardpassword" id="cardpassword" type="password" class="easyui-validatebox" required="true"></td></tr>
		<tr><td>重复密码：</td><td><input readonly="readonly" name="confirmPassword" id="confirmPassword" type="password" class="easyui-validatebox" required="true"></td></tr>
		<tr><td>电子钱包最大消费金额：</td><td><input name="moneycardlimit" class="easyui-numberbox" class="easyui-validatebox" required="true" value="1000" data-options="precision:0,groupSeparator:','"></td></tr>
		<tr>
			<td>电子账户充值金额：   </td><td><input onkeyup="doCount();" onchange="doCount();"  style="text-align:right;font-size: 23px;width: 150px;height: 28px;" maxlength="5" name="emoney" id="emoney" class="easyui-numberspinner" data-options="increment:10"  value="0" class="easyui-validatebox" required="true" ></td>
			<td>电子钱包充值金额：</td><td><input onkeyup="doCount();" onchange="doCount();" name="money" id="money" style="text-align:right;font-size: 23px;width: 150px;height: 28px;" maxlength="5" class="easyui-numberspinner" data-options="increment:10"  value="0" class="easyui-validatebox" required="true" ></td>
		</tr>
		<tr>
			<td>押金：</td><td><input name="selltax" id="selltax"  style="text-align:right;font-size: 23px;width: 150px;" maxlength="5"  readonly="readonly" ></td>
			<td>应收金额：</td><td  style="color: red;font-weight:bold;font-size: 23px;" align="center" id="mustMoney">30</td>
		</tr>
		<tr>
			<td>实收金额：</td><td><input  class="easyui-numberspinner" data-options="increment:10" id="trade" onkeyup="setGive();" style="text-align:right;font-size: 23px;width: 150px;" maxlength="5"  value="0" ></td>
			<td>找零：</td><td id="give" style="color: green;font-weight:bold;font-size: 23px;" align="center" >0</td>
		</tr>
	</table>
	<a href="#" id="btn-add" onclick="readCardInfo();" class="easyui-linkbutton" iconCls="icon-search">读卡</a>
	<a href="#" id="btn-back" onclick="closeWindow();" class="easyui-linkbutton" iconCls="icon-back">返回</a>
	<a href="#" id="btn-add" onclick="addOrUpdateUser();" class="easyui-linkbutton" iconCls="icon-save">保存</a>
</form>